<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <header style="height:100%">
            <div align="left">
                <table style="width: 100%">
                    <tr>
                        <td>
                            <form class="form-inline" onsubmit="return false">
                                <div class="form-group">
                                    ip：
                                    <input id="ip" type="text" class="form-control" placeholder="ip">
                                    <button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>
                                </div>
                            </form>
                        </td>
                        <td align="right">
                            <button class="layui-btn layui-btn-sm" onclick="location.href='addBlackIP.html'" permission="ip:black:save">
                                <i class="layui-icon">&#xe608;</i> 添加
                            </button>
                        </td>
                    </tr>
                </table>
            </div>
        </header>

        <div>
            <div class="widget-body no-padding">
                <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                        <tr>
                        </tr>
                    <tr>
                        <th>ip</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script src="../../js/constant.js"></script>
<script type="text/javascript" src="../../js/libs/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>

<script type="text/javascript">
    var pers = checkPermission();
    var example;

    layui.use(['layer','util'],function(){
        var layer = layui.layer;
        var util = layui.util;

        function init(){
            example = $("#dt-table").DataTable({
                "searching": false,
                "processing": false,
                "serverSide" : true,
                "ordering" :false,
                "language": {
                    "url": "../../js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url" : domainName + "/api-b/blackIPs",
                    "type":"get",
                    "data":function(d){
                        d.ip = $('#ip').val();
                    },
                    "dataSrc": function (json) {
                        json.recordsTotal=json.total;
                        json.recordsFiltered=json.total;
                        return json.data;
                    },
                    "error":function(xhr, textStatus, errorThrown){
                        var msg = xhr.responseText;
                        console.log(msg);
                        if (xhr.status == 400) {
                            layer.msg(JSON.parse(msg).message);
                        } else if (xhr.status == 401) {
                            localStorage.removeItem("token");
                            layer.msg("token过期，请重新登录", {shift: -1, time: 1000}, function(){
                                location.href = loginPage;
                            });
                        } else if (xhr.status == 403) {
                            layer.msg('未授权');
                        } else if (xhr.status == 500) {
                            var info = JSON.parse(msg);
                            var exception = info.exception;
                            var message = info.message;
                            layer.msg('系统错误：' + (exception ? exception : message));
                        }
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    { "data": "ip", "defaultContent": ""},
                    {
                        "data": "createTime",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            return util.toDateString(data);
                        }
                    },
                    {
                        "data": "",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            var id = row['ip'];
                            var del = buttonDel(id, "ip:black:delete", pers);

                            return del;
                        }
                    },
                ],
            });
        }
    });
</script>
</body>
</html>